1 using UnityEngine;
2 using
UnityEngine.UI;
3 using
System.Collections;
4
5
6 // Hi! This script presents the overlay info
for our tutorial content, linking you back to the relevant page.
7 public
class TutorialInfo : MonoBehaviour
8 {
9
10     
// allow user to choose whether to show this menu
11     
public bool showAtStart = true;
12
13     
// location that Visit Tutorial button sends the user
14     
public string url;
15
16     
// store the GameObject which renders the overlay info
17     
public GameObject overlay;
18
19     
// store a reference to the audio listener in the scene, allowing for muting of the scene during the overlay
20     
public AudioListener mainListener;
21
22     
// store a reference to the UI toggle which allows users to switch it off for future plays
23     
public Toggle showAtStartToggle;
24
25     
// string to store Prefs Key with name of preference for showing the overlay info
26     
public static string showAtStartPrefsKey = "showLaunchScreen";
27
28     
// used to ensure that the launch screen isn't more than once per play session if the project reloads the main scene
29     
private static bool alreadyShownThisSession = false;
30
31
32     
void Awake()
33     {
34         
// have we already shown this once?
35         
if(alreadyShownThisSession)
36         {
37             StartGame();
38         }
39         
else
40         {
41             alreadyShownThisSession =
true;
42
43             
// Check player prefs for show at start preference
44             
if (PlayerPrefs.HasKey(showAtStartPrefsKey))
45             {
46                 showAtStart = PlayerPrefs.GetInt(showAtStartPrefsKey) ==
1;
47             }
48
49             
// set UI toggle to match the existing UI preference
50             showAtStartToggle.isOn = showAtStart;
51
52             
// show the overlay info or continue to play the game
53             
if (showAtStart)
54             {
55                 ShowLaunchScreen();
56             }
57             
else
58             {
59                 StartGame ();
60             }
61         }
62     }
63
64     
// show overlay info, pausing game time, disabling the audio listener
65     
// and enabling the overlay info parent game object
66     
public void ShowLaunchScreen()
67     {
68         Time.timeScale =
0f;
69         mainListener.enabled =
false;
70         overlay.SetActive (
true);
71     }
72
73     
// open the stored URL for this content in a web browser
74     
public void LaunchTutorial()
75     {
76         Application.OpenURL (url);
77     }
78
79     
// continue to play, by ensuring the preference is set correctly, the overlay is not active,
80     
// and that the audio listener is enabled, and time scale is 1 (normal)
81     
public void StartGame()
82     {
83         overlay.SetActive (
false);
84         mainListener.enabled =
true;
85         Time.timeScale =
1f;
86     }
87
88     
// set the boolean storing show at start status to equal the UI toggle's status
89     
public void ToggleShowAtLaunch()
90     {
91         showAtStart = showAtStartToggle.isOn;
92         PlayerPrefs.SetInt(showAtStartPrefsKey, showAtStart ?
1 : 0);
93     }
94 }


Hi! This script presents the overlay info for our tutorial content, linking you back to the relevant page.

allow user to choose whether to show this menu

location that Visit Tutorial button sends the user

store the GameObject which renders the overlay info

store a reference to the audio listener in the scene, allowing for muting of the scene during the overlay

store a reference to the UI toggle which allows users to switch it off for future plays

string to store Prefs Key with name of preference for showing the overlay info

used to ensure that the launch screen isn't more than once per play session if the project reloads the main scene

have we already shown this once?

Check player prefs for show at start preference

set UI toggle to match the existing UI preference

show the overlay info or continue to play the game

show overlay info, pausing game time, disabling the audio listener

and enabling the overlay info parent game object

open the stored URL for this content in a web browser

continue to play, by ensuring the preference is set correctly, the overlay is not active,

and that the audio listener is enabled, and time scale is 1 (normal)

set the boolean storing show at start status to equal the UI toggle's status




Trò chơi giống như Rogue 2D sử dụng Unity 28.458 lượt xem

Gõ tìm kiếm nhanh...